import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.olap4j.OlapConnection;
import org.olap4j.OlapDatabaseMetaData;
import org.olap4j.OlapWrapper;
import org.olap4j.PreparedOlapStatement;
import org.olap4j.driver.xmla.XmlaOlap4jMeasure;
import org.olap4j.metadata.Cube;
import org.olap4j.metadata.Measure;

public class GetCubes {

	// public static String URL = ""
	public static final String URL = "jdbc:xmla:Server=http://10.20.14.40:9999/olap/msmdpump.dll;Catalog=\"烟草数据中心\"";
	public static final String USER = "\"datacenter\\\\yangchen\"";
	public static final String PASSWORD = "\"Neu_sdyc\"";

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws SQLException,
			ClassNotFoundException {
		Class.forName("org.olap4j.driver.xmla.XmlaOlap4jDriver");

		OlapConnection con = (OlapConnection) DriverManager.getConnection(URL,
				USER, PASSWORD);
		OlapWrapper wrapper = (OlapWrapper) con;
		OlapConnection olapConnection = (OlapConnection) wrapper
				.unwrap(OlapConnection.class);
		final OlapDatabaseMetaData metaData = olapConnection.getMetaData();
		final ResultSet cubes = metaData.getCubes(null, null, null);
		StringBuffer buffer = new StringBuffer();
		while (cubes.next()){
			final String cubeName = cubes.getString("CUBE_NAME");
			buffer.append(",").append(cubeName).append(":").append(cubeName);
		}
		System.out.println(buffer.deleteCharAt(0).toString());
	}
}
